﻿// ==UserScript==
// @name           attack_overview_villages_25
// @namespace      TribalWars
// @version        1.0
// @author         TribalWars
// @include        http://ae*.tribalwars.ae/game.php?*&screen=overview_villages&mode=combined
// @include        http://ae*.tribalwars.ae/game.php?*&screen=overview_villages
// @include        http://ae*.tribalwars.ae/game.php?*&mode=combined&group=*&page=*&screen=overview_villages
// @include        http://ae*.tribalwars.ae/game.php?*&mode=combined&group=*&screen=overview_villages
// ==/UserScript==



$("#combined_table tr").next().each(function(){
    var villageA = $(this).find("td:eq(1) a").attr("href").match(/village=\d+/);
    
    
    var url = '/game.php?'+villageA +'&screen=place';
    
    var yui = $(this).find("td:eq(0)");
    $(yui).html("<form target='_blank' id='units_form' name='units' action='' method='post'><input type='hidden' id='unit_input_spear' name='spear' style='width: 40px' tabindex='1' value='' class='unitsInput' type='text'><input type='hidden' id='unit_input_sword' name='sword' style='width: 40px' tabindex='2' value='' class='unitsInput' type='text'><input type='hidden' id='unit_input_axe' name='axe' style='width: 40px' tabindex='3' value='' class='unitsInput' type='text'><input type='hidden' id='unit_input_archer' name='archer' style='width: 40px' tabindex='4' value='' class='unitsInput' type='text'><input type='hidden' id='unit_input_spy' name='spy' style='width: 40px' tabindex='5' value='' class='unitsInput' type='text'><input type='hidden' id='unit_input_light' name='light' style='width: 40px' tabindex='6' value='' class='unitsInput' type='text'><input type='hidden' id='unit_input_marcher' name='marcher' style='width: 40px' tabindex='7' value='' class='unitsInput' type='text'><input type='hidden' id='unit_input_heavy' name='heavy' style='width: 40px' tabindex='8' value='' class='unitsInput' type='text'><input type='hidden' id='unit_input_ram' name='ram' style='width: 40px' tabindex='9' value='' class='unitsInput' type='text'><input type='hidden' id='unit_input_catapult' name='catapult' style='width: 40px' tabindex='10' value='' class='unitsInput' type='text'><input type='hidden' id='unit_input_knight' name='knight' style='width: 40px' tabindex='11' value='' class='unitsInput' type='text'><input type='hidden' id='unit_input_snob' name='snob' style='width: 40px' tabindex='12' value='' class='unitsInput' type='text'><input type='hidden' name='x' tabindex='13' id='inputx' value='' size='5' type='text'><input type='hidden' name='y' tabindex='14' id='inputy' value='' size='5' type='text'><input id='target_place' tabindex='15' class='attack btn btn-attack' name='place' value='نقطة التجمع' style='font-size: 10pt;' type='submit'></form>");
   $(this).find("#units_form").attr("action",url);		
});


$(".overview_table tbody tr th:eq(0)").html("<input id='tak' class='attack btn btn-attack' type='button' style='font-size: 10pt;' value='نقطة تجمع' name='place'></input>");



$(function(){
$("#tak").click(function(){
$(".vis.overview_table tr td:nth-child(1)").find(".btn-attack").click();
});
});



$(".vis_item").append("<center><table style='border:1px solid #7d510f;' align='center' width='86%'><thead><tr style='background-color:#C1A264;'><th style='text-align:center' width='35'><img src='/graphic/unit/unit_spear.png?48b3b'></th><th style='text-align:center' width='35'><img src='/graphic/unit/unit_sword.png?b389d'></th><th style='text-align:center' width='35'><img src='/graphic/unit/unit_axe.png?51d94'></th><th style='text-align:center' width='35'><img src='/graphic/unit/unit_archer.png?db2c3'></th><th style='text-align:center' width='35'><img src='/graphic/unit/unit_spy.png?eb866'></th><th style='text-align:center' width='35'><img src='/graphic/unit/unit_light.png?2d86d'></th><th style='text-align:center' width='35'><img src='/graphic/unit/unit_marcher.png?ad3be'></th><th style='text-align:center' width='35'><img src='/graphic/unit/unit_heavy.png?a83c9'></th><th style='text-align:center' width='35'><img src='/graphic/unit/unit_ram.png?2003e'></th><th style='text-align:center' width='35'><img src='/graphic/unit/unit_catapult.png?5659c'></th><th style='text-align:center' width='35'><img src='/graphic/unit/unit_knight.png?58dd0'></th><th style='text-align:center' width='35'><img src='/graphic/unit/unit_snob.png?0019c'></th><th style='text-align:center' width='35'>x:</th><th style='text-align:center' width='35'>y:</th></tr></thead><tbody><tr style='background-color: #F4E4BC;'><td><input id='spear' type='text' size='3'/></td><td><input id='sword' type='text' size='3'/></td><td><input id='axe' type='text' size='3'/></td><td><input id='archer' type='text' size='3'/></td><td><input id='spy' type='text' size='3'/></td><td><input id='light' type='text' size='3'/></td><td><input id='marcher' type='text' size='3'/></td><td><input id='heavy' type='text' size='3'/></td><td><input id='ram' type='text' size='3'/></td><td><input id='catapult' type='text' size='3'/></td><td><input id='knight' type='text' size='3'/></td><td><input id='sonbmen' type='text' size='3'/></td><td><input id='xxx' type='text' size='3'/></td><td><input id='yyy' type='text' size='3'/></td></tr></tbody><tr><td colspan='14'><center></center></td></tr></table></center>");

$("#target_place").click(function(){
    
    var spear = $("#spear").val();
    var sword = $("#sword").val();
    var axe =  $("#axe").val();
    var archer = $("#archer").val();
    var spy =  $("#spy").val();
    var light = $("#light").val();
    var marcher = $("#marcher").val();
    var heavy =  $("#heavy").val();
    var ram =   $("#ram").val();
    var catapult = $("#catapult").val();
    var knight = $("#knight").val();
    var snob =   $("#sonbmen").val();
    var xxx = $("#xxx").val();
    var yyy = $("#yyy").val();
	
	
	
    if(spear == '' && sword == '' && axe == '' && archer == '' && spy == '' && light == '' && marcher == '' && heavy == '' && ram == '' && catapult == '' && knight == '' && snob == ''){
        
        alert("لم تختر أي نوع من الوحدات");
    }else
    
        if(xxx == '' && yyy == '') {alert("لم تقم بادخال الإحداثيات");}
    
    
    
    
    
    
    else{
        
        $("#combined_table").each(function(){
            $(this).find("input[name=spear]").val(spear);
            $(this).find("input[name=sword]").val(sword);
            $(this).find("input[name=axe]").val(axe);
            $(this).find("input[name=archer]").val(archer);
            $(this).find("input[name=spy]").val(spy);
            $(this).find("input[name=light]").val(light);
            $(this).find("input[name=marcher]").val(marcher);
            $(this).find("input[name=heavy]").val(heavy);
            $(this).find("input[name=ram]").val(ram);
            $(this).find("input[name=catapult]").val(catapult);
            $(this).find("input[name=knight]").val(knight);
			$(this).find("input[name=snob]").val(snob);
            $(this).find("input[name=x]").val(xxx);
            $(this).find("input[name=y]").val(yyy);		
        });
    }
});

var $ = typeof unsafeWindow != 'undefined' ? unsafeWindow.$ : window.$;
$.ajaxSetup({ cache: true });
if(window.document.URL.match(/mode=combined/) == null){
	UI.InfoMessage('ستم نقلك لصفحة عمل السكربت',3000,true);
	var ID = window.document.URL.match(/\d+/g)[1];
	window.open("/game.php?village="+ID+"&screen=overview_villages&mode=combined","_self");
}